home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / magazyn_amiga / 6 / ami013a_komputerowa_hodowla.li < prev    next >
Text File  |  1997-09-16  |  2KB  |  183 lines

  1. /* listing nr 1 */
  2.  
  3. #include <intuition/intuition.h>
  4.  
  5. #include <functions.h>
  6.  
  7. #include <stdio.h>
  8.  
  9. #include <stdlib.h>
  10.  
  11. #include <math.h>
  12.  
  13. #define WIDTH 640
  14.  
  15. #define HEIGHT 256
  16.  
  17. #define x0 10
  18.  
  19. #define y0 210
  20.  
  21. struct Window *wind1;
  22.  
  23. struct Window *wind2;
  24.  
  25. struct IntuitionBase *IntuitionBase;
  26.  
  27. struct GfxBase *GfxBase;
  28.  
  29. struct NewWindow wind1_data={
  30.  
  31.     0,0,WIDTH,HEIGHT,1,1,CLOSEWINDOW,
  32.  
  33.     ACTIVATE|GIMMEZEROZERO|WINDOWCLOSE|WINDOWDRAG|WINDOWDEPTH,
  34.  
  35.     0,0,(UBYTE *)"Zmiana iloôci w czasie",0,0,
  36.  
  37.     200,256,WIDTH,HEIGHT,WBENCHSCREEN};
  38.  
  39. struct NewWindow wind2_data={
  40.  
  41.     0,256,WIDTH,HEIGHT,1,1,CLOSEWINDOW,
  42.  
  43.     ACTIVATE|GIMMEZEROZERO|WINDOWCLOSE|WINDOWDRAG|WINDOWDEPTH,
  44.  
  45.     0,0,(UBYTE *)"Stosunek iloôci",0,0,
  46.  
  47.     200,256,WIDTH,HEIGHT,WBENCHSCREEN};
  48.  
  49. void koniec(void)
  50.  
  51. {
  52.  
  53.     if (wind1) CloseWindow(wind1);
  54.  
  55.     if (wind2) CloseWindow(wind2);
  56.  
  57.     if (GfxBase)
  58.  
  59.         CloseLibrary((struct Library *)GfxBase);
  60.  
  61.     if (IntuitionBase)
  62.  
  63.         CloseLibrary((struct Library *)IntuitionBase);
  64.  
  65.     exit(0);
  66.  
  67. }
  68.  
  69. void OpenAllLibraries(void)
  70.  
  71. {
  72.  
  73.     IntuitionBase=(struct IntuitionBase *)
  74.  
  75.         OldOpenLibrary("intuition.library");
  76.  
  77.     if (!IntuitionBase) exit(100);
  78.  
  79.     GfxBase=(struct GfxBase *)
  80.  
  81.         OldOpenLibrary("graphics.library");
  82.  
  83.     if (!GfxBase) exit(100);
  84.  
  85. }
  86.  
  87. int x(int X)
  88.  
  89. {
  90.  
  91.     return(X+x0);
  92.  
  93. }
  94.  
  95. int y(int Y)
  96.  
  97. {
  98.  
  99.     return(y0-Y);
  100.  
  101. }
  102.  
  103. main(int argc,char *argv[])
  104.  
  105. {
  106.  
  107.     float scale=WIDTH/20000.0;
  108.  
  109.     int t; /* czas */
  110.  
  111.     float w,k; /* wilki i króliki */
  112.  
  113.     float w1,k1; /* zmiany liczebnoôci */
  114.  
  115.     if(argc!=3)
  116.  
  117.     {
  118.  
  119.         printf("Argumenty: w k\n");
  120.  
  121.         exit(0);
  122.  
  123.     }
  124.  
  125.     OpenAllLibraries();
  126.  
  127.     if(!(wind1=OpenWindow(&wind1_data))) koniec();
  128.  
  129.     if(!(wind2=OpenWindow(&wind2_data))) koniec();
  130.  
  131.     Move(wind1->RPort,x(0),y(0));
  132.  
  133.     Draw(wind1->RPort,x(0),y(200));
  134.  
  135.     Move(wind1->RPort,x(0),y(0));
  136.  
  137.     Draw(wind1->RPort,x(620),y(0));
  138.  
  139.     Move(wind2->RPort,x(0),y(0));
  140.  
  141.     Draw(wind2->RPort,x(0),y(200));
  142.  
  143.     Move(wind2->RPort,x(0),y(0));
  144.  
  145.     Draw(wind2->RPort,x(620),y(0));
  146.  
  147.     w = atof(argv[1]);
  148.  
  149.     k = atof(argv[2]);
  150.  
  151.     for(t=1;t<20000;t++)
  152.  
  153.     {
  154.  
  155.         SetAPen(wind1->RPort,1);
  156.  
  157.         WritePixel(wind1->RPort,x((int)(t*scale)), y((int)(w/15.0)));
  158.  
  159.         SetAPen(wind1->RPort,2);
  160.  
  161.         WritePixel(wind1->RPort,x((int)(t*scale)), y((int)(k/15.0)));
  162.  
  163.         SetAPen(wind2->RPort,1);
  164.  
  165.         WritePixel(wind2->RPort,x((int)(k/10.0)), y((int)(w/10.0)));
  166.  
  167.         w1=w-0.002*w+0.000002*w*k;
  168.  
  169.         k1=k-0.00002*w*k+0.002*k;
  170.  
  171.         w=w1;
  172.  
  173.         k=k1;
  174.  
  175.     }
  176.  
  177.     Wait(1<<wind1->UserPort->mp_SigBit);
  178.  
  179.     koniec();
  180.  
  181. }
  182.  
  183.